package cn.wolfcode.shop.service.impl;

import cn.wolfcode.shop.domain.PropertyValue;
import cn.wolfcode.shop.mapper.PropertyValueMapper;
import cn.wolfcode.shop.service.IPropertyValueService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class PropertyValueServiceImpl implements IPropertyValueService {
    @Autowired
    private PropertyValueMapper propertyValueMapper;
    /**
     * 商品属性值
     * @param PropertyId
     * @return
     */
    @Override
    public List<PropertyValue> selectByPropertyId(Long PropertyId) {
        return propertyValueMapper.selectByPropertyId(PropertyId);
    }

    /**
     * 保存或修改商品属性值
     * @param propertyValues
     */
    @Override
    public void saveOrUpdate(List<PropertyValue> propertyValues) {
        for (PropertyValue propertyValue : propertyValues) {
            if(propertyValue.getId()!=null){
                propertyValueMapper.updateByPrimaryKey(propertyValue);
            }else {
                propertyValueMapper.insert(propertyValue);
            }
        }
    }
}
